/**
 * 
 */
package com.byzk.p2p.admin.user.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.byzk.p2p.admin.base.util.DateUtils;
import com.byzk.p2p.admin.base.util.PageInfo;
import com.byzk.p2p.admin.user.dao.UserInfoDao;
import com.byzk.p2p.admin.user.dto.UserInfoDto;

/*** <p>Title:UserInfoService </p>
* <p>Description: 用户信息管理服务类</p>
* <p>Company:xbd </p>
* @author:Administrator
* @date:2016年10月18日下午5:32:54 */
@Service
public class UserInfoService {

	@Autowired
	private  UserInfoDao userInfoDao;
	/**
	 * 
	* <p>Description:客户资料信息查询 </p>
	* <p>Company:xbd </p>
	* @author:lilei
	* @date:2016年10月19日上午10:02:15
	 */
	public PageInfo<UserInfoDto> userInfoList(Map<String, Object> reqParam, Integer index, Integer limit) {

		if(reqParam==null){
			reqParam = new HashMap<String,Object>();
		}
		reqParam.put("start",index);
		reqParam.put("limit",limit);
		Integer count = userInfoDao.count(reqParam);
		reqParam.put("start",((index==1 && index!=null)?0:index));
		List<UserInfoDto> userList = userInfoDao.ListUserInfo(reqParam);
		PageInfo<UserInfoDto> pageInfo = new PageInfo<UserInfoDto>(count,index,limit);
		pageInfo.setPageList(userList);
		return pageInfo;
	}
	
	/**
	 * 
	 * <p>
	 * Description:客户资料信息查询
	 * </p>
	 * <p>
	 * Company:xbd
	 * </p>
	 * 
	 * @author:lilei
	 * @date:2016年10月19日上午10:02:15
	 */
	public Integer updateOrSave(UserInfoDto dto) {

		Map<String, Object> reqParam = new HashMap<String, Object>();
		Integer result = null;
		if (dto != null && dto.getUid() != null) {
			reqParam.put("uid", dto.getUid());
			reqParam.put("start",0);
			reqParam.put("limit",10);
			List<UserInfoDto> userList = userInfoDao.ListUserInfo(reqParam);
			if (userList != null && userList.size() > 0) {
				UserInfoDto info = userList.get(0);
				if (info.getBankCode() != null) {
					dto.setCreateTime(DateUtils.getNowTimeString());
					result = userInfoDao.updateUserInfo(dto);
				} else {
					dto.setIsDelete(0);
					dto.setTerminal("PC");
					dto.setCreateTime(DateUtils.getNowTimeString());
					result = userInfoDao.bindBankCard(dto);
				}
			}
		}
		return result;
	}
}
